package flexibility;

import gui.loginScreen;

import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class sendMail {

	private loginScreen ls = new loginScreen();

	public void sendEmail(String userEmail, String password, int type)
			throws Exception {
		String host = "smtp.gmail.com";
		String from = "Academic.Information.System.G4";
		String pass = "N3wB0ss!";
		Properties props = System.getProperties();
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.host", host);
		props.put("mail.smtp.user", from);
		props.put("mail.smtp.password", pass);
		props.put("mail.smtp.port", "25");
		props.put("mail.smtp.auth", "true");
		
		Session session = Session.getDefaultInstance(props, null);
		MimeMessage message = new MimeMessage(session);
		message.setFrom(new InternetAddress(from));

		message.addRecipient(Message.RecipientType.TO, new InternetAddress(
				userEmail));

		// To get the array of addresses

		message.setSubject("your password to Academic Information System");
		message.setText("Your password is " + password);
		Transport transport = session.getTransport("smtp");
		transport.connect(host, from, pass);
		transport.sendMessage(message, message.getAllRecipients());
		transport.close();
		System.out.println(userEmail);
		switch (type) {
		case 1:
			ls.showMessages(
					"New Master password was sent to your email address\n Please type it as your password to log in",
					"Login failure troubleshoot", 2);
			break;
		case 2:
			ls.showMessages("Your password was sent to your email address (" + userEmail+")",
					"Password recovery confirmation", 2);
			
			break;
		}

	}
}
